const express = require('express');
const app = express();
const path = require('path');

// 设置静态文件目录为项目根目录的 public 文件夹
app.use(express.static(path.join(__dirname, 'public')));

// 处理根路径的路由
app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'public', 'Login.html'));
});

// 启动服务器
const PORT = process.env.PORT || 8081;
app.listen(PORT, async () => {
    console.log(`Server is running on port ${PORT}`);

    try {
        // 动态导入 open 模块并打开浏览器访问本地服务器
        const open = await import('open');
        open.default(`http://localhost:${PORT}`);
    } catch (error) {
        console.error('Error opening browser:', error);
    }
});
